import itertools
import pyzipper

filename = "D:\\BaiduNetdiskDownload\\2023\\2.zip"
passwd = ""
size = 5

def extract_zip(zip_file, password):
    try:
        # 打开加密的ZIP文件
        with pyzipper.AESZipFile(zip_file) as zf:
            # 尝试使用密码打开
            zf.pwd = password.encode('utf-8')

            # 解压所有文件
            zf.extractall()
            print("解压成功！")
        return True
    except RuntimeError as e:
        print("密码错误或无法打开文件:", e)
        return False
    except Exception as e1:
        print("密码错误或无法打开文件:", e1)
        return False
chars = "1234567890abcdefghijklmnopqrstuvwsyzABCDEFGHIJKLMNOPQRSTUVWSYZ!#$%&'()*+,-./:;<=>?@[]^_{|}~`"
for c in itertools.permutations(chars, size):
    passwd = "".join(c)
    print("passwd: ", passwd)
    result = extract_zip(filename, passwd)
    if not result:
        print("no", passwd)
    else:
        print("yes", passwd)
        break
